package com.mindframe.MapasGoogle;

import java.util.List;

import android.graphics.Point;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;



public class MapasGoogle extends MapActivity {

	private MapView mapa = null;
	private Button btnSatelite = null;
	private Button btnDatos = null;
	private Button btnCentrar = null;
	private MapController controlMapa = null;
	private Button btnMover = null;
	
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_mapas_google);
        
        btnSatelite = (Button)findViewById(R.id.btnSatelite);
        btnDatos = (Button)findViewById(R.id.btnDatos);
        btnCentrar = (Button)findViewById(R.id.btnCentrar);
        btnMover = (Button)findViewById(R.id.btnMover);
        
        mapa = (MapView)findViewById(R.id.mapa);
        
        List<Overlay> capas = mapa.getOverlays();
        OverlayMapa om = new OverlayMapa();
        capas.add(om);
        mapa.postInvalidate();
        
        mapa.setBuiltInZoomControls(true);
        controlMapa = mapa.getController();
        
      
        
        
        btnSatelite.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(mapa.isSatellite()){
					mapa.setSatellite(false);
				}else{
					mapa.setSatellite(true);
				}
				mapa.getOverlays().clear();
			}
		});
        
        btnDatos.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				
				GeoPoint loc =  mapa.getMapCenter();
				
				Log.d("Latitud:", String.valueOf(loc.getLatitudeE6()));
				Log.d("Longitud:", String.valueOf(loc.getLongitudeE6()));
				
			}
		});
        
        btnCentrar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				Double lat = 36.77*1E6;
				Double lon = -6.35*1E6;
				
				Projection proj = mapa.getProjection();
				
				GeoPoint loc = new GeoPoint(lat.intValue(), lon.intValue());
				
				Point centro = new Point();
				proj.toPixels(loc, centro);
				
				
				
				controlMapa.animateTo(loc);
				
				int zoomAct = mapa.getZoomLevel();
				
				for(int i = zoomAct; i <= 15; i++){
					controlMapa.zoomIn();
				}
				
					
			}
		});
        
        btnMover.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				controlMapa.scrollBy(0, 10);
				
			}
		});
        
        
        
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_mapas_google, menu);
        return true;
    }
    
//    @Override
//	public boolean onTap(GeoPoint point, MapView mapView) {
//		Context contexto = mapView.getContext();
//		String msg = "Lat: " + point.getLatitudeE6() / 1E6 + " - " + "Lon: "
//				+ point.getLongitudeE6() / 1E6;
//		Toast toast = Toast.makeText(contexto, msg, Toast.LENGTH_SHORT);
//		toast.show();
//		return true;
//	}


	@Override
	protected boolean isRouteDisplayed() {
		// TODO Auto-generated method stub
		return false;
	}

    
}
